<?php session_start(); ?><!DOCTYPE html>
<!--
(JANGKRIK POLLING) - SISTEM VOTING DAN EVALUASI ASISTEN - FASDT (FORUM ASISTEN SOFTWARE DEVELOPMENT TEAM)
OLEH AGUS SIGIT WISNU 
aswzen@bk.ru / asw.web.id / aswishnu.blog.amikom.ac.id
пожалуйста, не взломать его.
-->
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>

	<!-- Basic Page Needs
  ================================================== -->
	<meta charset="utf-8">
	<title>Control Panel - Sivea</title>
	<meta name="description" content="">
	<meta name="author" content="Sigit" >

	<script type="text/javascript" src="jquery.js"></script>
	<script type="text/javascript" src="jquery-impromptu.js"></script>
	
	<!-- CSS
  ================================================== -->
	<link rel="stylesheet" href="../style/base.css">
	<link rel="stylesheet" media="all" type="text/css" href="jquery-impromptu.css" />

	<!-- Favicons
	================================================== -->
	<link rel="shortcut icon" href="../style/images/favicon.ico">


</head>
<?php

	include("dboper.php");
	$selectedjaprak="";
	if(isset($_POST['cekjadwal'])){
				$sesi=mysql_real_escape_string($_POST['txtSesi']);
				$kelas=mysql_real_escape_string($_POST['txtNamaKelas']);
				$makul=mysql_real_escape_string($_POST['txtNamaMakul']);
				$hari=mysql_real_escape_string($_POST['txtHari']);
				$selectedjaprak=getIdJaprak($hari,$sesi,$makul,$kelas);
				if($selectedjaprak!="gagal"){
					$d_japrak = getOneJaprak($selectedjaprak);
					$h_asisten = getAllAsistenOlah($selectedjaprak);
				}else{
					?>
					<script>
						alert("Jadwal tidak terdaftar");
					
					</script>
					<?php
				}
	}

	$d_sesi	  = getAllSesi();
	$d_matkul = getAllMatkul();
	$d_kelas  = getAllKelas();
	
	
	
	

?>
<body>

<?php $hari_arr= array("Senin","Selasa","Rabu","Kamis","Jumat","Sabtu");
	  $idhari_arr= array("SN","SL","RB","KM","JM","SB");
		?>
	<div class="container">
		<div class="formbox">
			<div class="fb_header"><img src="../style/images/logo.gif" width="25px"> Control Panel - Sivea</div><div class="fb_statusbar"><div id="status"></div></div>	
			<hr>
			<div class="fb_info">Olah Jadwal</div>
			<hr>
			
			<div class="fb_content" id="fb_content">
			
			<?php 
			///////////////////////////////////////PILIH JADWAL\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
			
			
			if(!isset($_GET['japrak']) && !isset($_GET['asisten'])){ ?>
			<form method="post" action="" name="pilihjadwal">
				<table>
				<tr><td>Hari</td><td>
		<select required="" name="txtHari" style="width:100px" type="text">
				<?php
					for($i=0;$i<sizeof($hari_arr);$i++){
					$selected="";
					if($idhari_arr[$i]==$d_japrak['hari']){
						$selected="selected";
					}
				?>
				 <option <?php echo $selected; ?> value="<?php echo $idhari_arr[$i];?>" ><?php echo $hari_arr[$i]; ?></option>
				<?php
					}
				?>
			 <!--<option value="SN" >Senin</option>
              <option value="SL" >Selasa</option>
              <option value="RB" >Rabu</option>
              <option value="KM" >Kamis</option>
              <option value="JM" >Jumat</option>
              <option value="SB" >Sabtu</option>-->
            </select>
			</td></tr>
		<tr><td>Sesi</td><td>
		<select required="" name="txtSesi" style="width:130px" type="text">
              <option >pilih</option>
			  <?php for($i=0;$i<sizeof($d_sesi);$i++){ 
					$selected="";
					if($d_sesi[$i]['id_sesi']==$d_japrak['id_sesi']){
						$selected="selected";
					}
			  ?>
					
					<option <?php echo $selected; ?> value="<?php echo $d_sesi[$i]['id_sesi']?>" ><?php echo $d_sesi[$i]['jam_mulai']."-".$d_sesi[$i]['jam_selesai']?></option>
			  <?php } ?>
            </select>
			</td></tr>
		<tr><td>Kelas</td><td>
        <select required="" name="txtNamaKelas" style="width:100px" >
              <option value="" >pilih</option>
             <?php for($i=0;$i<sizeof($d_kelas);$i++){ 
					$selected="";
					if($d_kelas[$i]['id_kelas']==$d_japrak['id_kelas']){
						$selected="selected";
					}
			 ?>
					<option <?php echo $selected; ?> value="<?php echo $d_kelas[$i]['id_kelas'];?>" ><?php echo $d_kelas[$i]['nama_kelas'];?></option>
			  <?php } ?>
            </select>  	
			</td></tr>
		<tr><td>Matakuliah</td><td>
		<select required="" name="txtNamaMakul" style="width:200px" type="text">
              <option >pilih</option>
			   <?php for($i=0;$i<sizeof($d_matkul);$i++){ 
					$selected="";
					if($d_matkul[$i]['id_matkul']==$d_japrak['id_matkul']){
						$selected="selected";
					}
			   ?>
					
					<option <?php echo $selected ?> value="<?php echo $d_matkul[$i]['id_matkul'];?>" ><?php echo $d_matkul[$i]['jurusan']." - ".$d_matkul[$i]['nama_matkul'];?></option>
			  <?php  }?>
            </select>
			</td></tr>
			</table>
			<input type="hidden" name="cekjadwal" value="true"/>
			 <input type="submit" value="CEK" />
			 
	</form>
	<?php
	
	if(isset($_POST['cekjadwal']) && isset($h_asisten)){ 
			
	?>		
			<table border="solid">
			<tr><td>Nama</td><td>NIM</td><td>FOTO</td><td>PROSES</td></tr>
			 <?php while ($d_asisten = mysql_fetch_array($h_asisten)) {
		echo '<tr>
				<td>'.$d_asisten['nama_asisten'].'</td>
				<td>'.$d_asisten['nim_asisten'].'</td>'.
				'<td><a rel="prettyPhoto" href="http://www.amikom.ac.id/public/fotomhs/20'.
				substr($d_asisten['nim_asisten'],0,2).'/'.
				$d_asisten['nim_asisten'].'.jpg" title="&nbsp&nbsp'.
				$d_asisten['Nama'].' ('.$d_asisten['NIM'].
				')" ><img src="http://www.amikom.ac.id/public/fotomhs/20'.
				substr($d_asisten['nim_asisten'],0,2).'/'.
				$d_asisten['nim_asisten'].'.jpg" title="&nbsp&nbsp'.
				$d_asisten['nama_asisten'].' ('.$d_asisten['nim_asisten'].')" width="25" /></a></td>
				<td><a href="?japrak='.$selectedjaprak.'&asisten='.$d_asisten['id_asisten'].'">Ubah</a> </td>
				
				</tr>';	
	} 
?>
</table>
<?php }
}else{
	///////////////////////////////////////EDIT JADWAL\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
	$d_japrak = getDetailJaprak($_GET['japrak']);		
	$d_asisten= getDetailAsisten($_GET['asisten']);
	$a_asisten= getAllAsistenPerMatkul($d_japrak['id_matkul']);
	$d_ngasisten=getNgasistenJaprak($_GET['japrak']);
 ?>
 <table>
 <tr>
 <td><b>Hari</b></td>
 <td><?php echo $d_japrak['hari']; ?></td>
 </tr>
 <tr>
 <td><b>Sesi</b></td>
 <td><?php echo $d_japrak['jam_mulai']."-".$d_japrak['jam_selesai']; ?></td>
 </tr>
 <tr>
 <td><b>Matakuliah</b></td>
 <td><?php echo $d_japrak['nama_matkul']; ?></td>
 </tr>
 <form name="formUbahJadwalAsisten" method="post" action="olahjadwal.php">
 <input type="hidden" name="txtJaprak" value="<?php echo $d_japrak['id_japrak']; ?>" />
 <input type="hidden" name="txtJmlAsisten" value="<?php echo sizeof($d_ngasisten);?>" />
 
 <?php for($a=0;$a<sizeof($d_ngasisten);$a++){ ?>
	<tr>
	<td><?php if($a==0){echo "<b>Asisten</b>";} ?></td>
	<td>
	<input type="hidden" name="txtAsistenOld<?php echo $a; ?>" value="<?php echo $d_ngasisten[$a]['id_asisten']; ?>"/>
	<select required="" name="txtAsisten<?php echo $a; ?>" style="width:300px" type="text">
              <option >pilih</option>
			   <?php for($i=0;$i<sizeof($a_asisten);$i++){ 
					$selected="";
					if($a_asisten[$i]['id_asisten']==$d_ngasisten[$a]['id_asisten']){
						$selected="selected";
					}
			   ?>
					<option <?php echo $selected ?> value="<?php echo $a_asisten[$i]['id_asisten'];?>" ><?php echo $a_asisten[$i]['nim_asisten']." - ".$a_asisten[$i]['nama_asisten'];?></option>
			  <?php } ?>
            </select>
		</td>
	</tr>
	<?php } ?>
	
 </table>
  <input type="submit" value="Ubah" name="submitUbah" />
 </form>
<?php } ?>

			</div>
			<hr>
			<center>Forum Asisten STMIK Amikom Yogyakarta &copy; 2014</center>
		</div>
	</div>
</body>

<?php
if(isset($_POST['submitUbah'])){
	$berhasil=false;
	$ada_rubah=false;
	for($i=0;$i<$_POST['txtJmlAsisten'];$i++){
		//kalau berbeda baru diupdate
		if($_POST['txtAsistenOld'.$i]!=$_POST['txtAsisten'.$i]){
			$ada_rubah=true;
			if(updateJadwalNgasisten($_POST['txtJaprak'],$_POST['txtAsistenOld'.$i],$_POST['txtAsisten'.$i])){
				$berhasil=true;
				
			}else{
				$berhasil=false;
			}
		}
		
	}
	if($berhasil){
		echo "<script>alert('Berhasil ubah jadwal asisten');</script>";
	}else if(!$ada_rubah && !$berhasil){
		echo "<script>alert('Tidak ada perubahan jadwal asisten');</script>";
	}else{
		echo "<script>alert('Gagal ubah jadwal asisten');</script>";
	}
	
}

 ?>	
</html>
